<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/27
 * Time: 18:36
 */
class Self_admin extends MY_Admin_Controller
{
    function __construct()
    {
        parent::__construct();
    }
    function gets(){
        $p_id = $this->input->get('p_id');
        if(!$p_id)
            $this->json_response(false);
        $this->load->config('recommend');
        $source_config = $this->config->item('source');

        if(!isset($source_config[$p_id])){
            $this->json_response(true);
        }

        $this->load->model($source_config[$p_id]['path']);

        $condition = array(
            'is_del'    =>  0
        );

        $model_name = ucfirst($source_config[$p_id]['model']);
        $result = $this->$model_name->fetch_array(
            $condition,
            $source_config[$p_id]['field']
        );
        foreach($result as &$v){
            if($p_id=='s1' && array_key_exists('articles_id',$v)){
                $v['id']=$v['articles_id'];
                continue;
            }
            if($p_id=='s2' && array_key_exists('activity_id',$v)){
                $v['id']=$v['activity_id'];
                continue;
            }
            if($p_id=='s3' && array_key_exists('lecturer_id',$v)){
                $v['id']=$v['lecturer_id'];
                continue;
            }
            if($p_id=='s4' && array_key_exists('place_id',$v)){
                $v['id']=$v['place_id'];
                continue;
            }
            unset($v);
        }
        if(!$result){
            $this->json_response(false);
        }
        $this->json_response(true,$result);
    }
    
}